"""
@Author  : 康帅
@Time    : 2021/7/5 15:48
@Function: 处理多个异常的三种方式
"""


def first():
    """
    第一种方法需要把所有可能发生的异常放到一个元组里
    :return:
    """
    try:
        file = open('test.txt', 'rb')
    except (IOError, EOFError) as e:
        print(f"异常{e.args[-1]}")


def second():
    """
    对每个单独的异常在单独的except语句块中处理
    :return:
    """
    try:
        file = open('test.txt', 'rb')
    except EOFError as e:
        print("EOF异常")
        raise e
    except IOError as e:
        print("IO异常")
        raise e


def third():
    """
    捕获所有异常
    :return:
    """
    try:
        file = open('test.txt', 'rb')
    except Exception as e:
        raise e


def fourth_finally():
    """
    finally
    不管是否抛出异常都会触发执行
    :return:
    """
    try:
        file = open('test.txt', 'rb')
    except IOError as e:
        print(f'IOError{e.args[-1]}')
    finally:
        print("无论是否发生异常，都会打印")
